﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace API_CIC.Activos
{
    public partial class GestionActivos : System.Web.UI.Page
    {


        protected void Page_Load(object sender, EventArgs e)
        {
            Calendario.SelectedDate = DateTime.Today;
            CalendarioModificar.SelectedDate = DateTime.Today;
        }

        protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
        {
            MultiView1.ActiveViewIndex = Int32.Parse(e.Item.Value);
            if (e.Item.Value == "0")
            {
                txtCantidadIngresar.Text = "";
                txtCodigo.Text = "";
                txtDescripcion.Text = "";
                Calendario.SelectedDate = DateTime.Today;
                txtNombre.Text = "";
                txtMarca.Text = "";
            }
                
        }

        protected void btnIngresar_Click(object sender, EventArgs e)
        {
            CapaControl.cActivosControl.IngresarActivo(txtCantidadIngresar.Text, txtCodigo.Text, 
                                                        txtDescripcion.Text, Calendario.SelectedDate,
                                                        txtNombre.Text, txtMarca.Text);
            Menu1.Items[0].Selected = true;
            MultiView1.ActiveViewIndex = 1;
            GridView1.DataBind();
        }

        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            CapaControl.cActivosControl.ModificarActivo(GridView1.SelectedValue.ToString(),txtCantidadModificar.Text,
                                        txtCodigoModificar.Text, txtDescripcionModificar.Text, txtMarcaModificar.Text,
                                        CalendarioModificar.SelectedDate, txtNombreModificar.Text);
            Menu1.Items[0].Selected = true;
            MultiView1.ActiveViewIndex = 1;
            GridView1.DataBind();
        }

        

        protected void btnModificar_Click(object sender, EventArgs e)
        {
            SGAPFACTIVO activo = CapaDatos.cActivosDatos.GetActivo(Int32.Parse(GridView1.SelectedValue.ToString()));
            txtNombreModificar.Text = activo.NOM_ACTIVO;
            txtMarcaModificar.Text = activo.TXT_MARCA;
            txtDescripcionModificar.Text = activo.DSC_ACTIVO;
            txtCodigoModificar.Text = activo.COD_ACTIVO.ToString();
            txtCantidadModificar.Text = activo.CAN_ACTIVO.ToString();
            if (activo.FEC_INGRESO!=null)
                CalendarioModificar.SelectedDate = (DateTime)activo.FEC_INGRESO;

            MultiView1.ActiveViewIndex = 2;
        }
    }
}